package com.taobao.message.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.taobao.message.model.po.Friendships;
import com.taobao.message.model.po.Messages;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 商品Mapper接口
 */
public interface MessagesMapper extends BaseMapper<Messages> {


    /**
     * 根据双方id 查询聊天记录(最后一条)
     */
    @Select("select * from messages where ((sender_id = #{senderId} and receiver_id = #{receiverId}) or (sender_id = #{receiverId} and receiver_id = #{senderId}) and is_new = 1)")
    Messages selectByUserIdAndFriendId(@Param("senderId") String senderId, @Param("receiverId") String receiverId);

    /**
     * 根据双方id 查询聊天记录(最后一条)
     */
    @Select("select * from messages where ((sender_id = #{senderId} and receiver_id = #{receiverId}) or (sender_id = #{receiverId} and receiver_id = #{senderId})) ORDER BY send_time")
    List<Messages> getChatRecord(@Param("senderId") String senderId, @Param("receiverId") String receiverId);

}
